/* Chat Widget Styles - Black & White Theme */
.chat-widget {
    position: fixed;
    bottom: 20px;
    right: 20px;
    z-index: 1000;
    font-family: 'Open Sans', sans-serif;
}

.chat-toggle {
    width: 60px;
    height: 60px;
    border-radius: 50%;
    background: #000000;
    border: 2px solid #ffffff;
    color: white;
    font-size: 24    .chat-input-container {
        padding: 15px 20px;
        border-radius: 0;
        position: fixed;
        bottom: 0;
        left: 0;
        right: 0;
        z-index: 999;
        background: #ffffff;
        border-top: 2px solid #000000;
        display: flex;
        gap: 10px;
        align-items: center;
        box-sizing: border-box;
        isolation: isolate; /* Create new stacking context */
    } pointer;
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.8);
    transition: all 0.3s ease;
    display: flex;
    align-items: center;
    justify-content: center;
    position: relative;
    overflow: hidden;
}

.chat-toggle::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: transparent;
    transform: translateX(-100%);
    transition: transform 0.6s;
}

.chat-toggle:hover::before {
    transform: translateX(100%);
}

.chat-toggle:hover {
    transform: scale(1.1);
    background: #333333;
    box-shadow: 0 6px 25px rgba(0, 0, 0, 0.9);
}

.chat-toggle.active {
    background: #ffffff;
    color: #000000;
    border: 2px solid #000000;
}

.chat-window {
    position: absolute;
    bottom: 80px;
    right: 0;
    width: 350px;
    height: 450px;
    background: #ffffff;
    border-radius: 8px;
    box-shadow: 0 10px 40px rgba(0, 0, 0, 0.5);
    display: none;
    flex-direction: column;
    overflow: hidden;
    border: 3px solid #000000;
}

.chat-window.active {
    display: flex;
    animation: slideInUp 0.3s ease-out;
}

@keyframes slideInUp {
    from {
        transform: translateY(20px);
        opacity: 0;
    }
    to {
        transform: translateY(0);
        opacity: 1;
    }
}

.chat-header {
    background: #000000;
    color: #ffffff;
    padding: 15px 20px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    border-bottom: 2px solid #000000;
}

.chat-header h4 {
    margin: 0;
    font-size: 16px;
    font-weight: 600;
}

.chat-close {
    background: none;
    border: none;
    color: #ffffff;
    font-size: 18px;
    cursor: pointer;
    padding: 0;
    width: 24px;
    height: 24px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 50%;
    transition: background-color 0.2s;
}

.chat-close:hover {
    background-color: rgba(255, 255, 255, 0.2);
}

.chat-messages {
    flex: 1;
    padding: 20px;
    overflow-y: auto;
    background: #ffffff;
    border-left: 1px solid #000000;
    border-right: 1px solid #000000;
    scroll-behavior: smooth;
    -webkit-overflow-scrolling: touch; /* iOS smooth scrolling */
}

.chat-message {
    margin-bottom: 15px;
    display: flex;
    align-items: flex-end;
}

.chat-message.user {
    justify-content: flex-end;
}

.chat-message.system,
.chat-message.admin {
    justify-content: flex-start;
}

.message-bubble {
    max-width: 80%;
    padding: 12px 16px;
    border-radius: 8px;
    font-size: 14px;
    line-height: 1.4;
    position: relative;
    animation: fadeInUp 0.3s ease-out;
    border: 2px solid #000000;
}

.chat-message.user .message-bubble {
    background: #000000;
    color: #ffffff;
    border-bottom-right-radius: 2px;
}

.chat-message.system .message-bubble,
.chat-message.admin .message-bubble {
    background: #ffffff;
    color: #000000;
    border-bottom-left-radius: 2px;
}

.chat-message.admin .message-bubble {
    background: #000000;
    color: #ffffff;
    border: 2px solid #ffffff;
}

.message-time {
    font-size: 11px;
    opacity: 0.6;
    margin-top: 4px;
    text-align: right;
}

.chat-message.system .message-time,
.chat-message.admin .message-time {
    text-align: left;
}

.chat-message.admin .message-time {
    color: rgba(255, 255, 255, 0.8);
    text-align: left;
}

.chat-input-container {
    padding: 15px 20px;
    background: #ffffff;
    border-top: 2px solid #000000;
    display: flex;
    gap: 10px;
    align-items: center;
    position: relative;
    z-index: 10;
}

.chat-input {
    flex: 1;
    border: 2px solid #000000;
    border-radius: 4px;
    padding: 10px 15px;
    font-size: 14px;
    outline: none;
    transition: border-color 0.2s;
    background: #ffffff;
    color: #000000;
}

.chat-input:focus {
    border-color: #333333;
    background: #ffffff;
}

.chat-send {
    background: #000000;
    border: 2px solid #000000;
    color: #ffffff;
    width: 40px;
    height: 40px;
    border-radius: 4px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s;
    position: relative;
    z-index: 100;
}

.chat-send i,
.chat-send .fa {
    color: #ffffff;
    font-size: 14px;
    pointer-events: none;
}

.chat-send:hover {
    background: #333333;
    transform: scale(1.05);
}

.chat-send:hover i,
.chat-send:hover .fa {
    color: #ffffff;
}

.chat-send:disabled {
    opacity: 0.5;
    cursor: not-allowed;
    transform: none;
    background: #666666;
}

.typing-indicator {
    padding: 10px 20px;
    color: #333333;
    font-size: 12px;
    font-style: italic;
    background: #ffffff;
    border-top: 1px solid #000000;
    position: relative;
    z-index: 5;
}

.typing-dots {
    display: inline-block;
}

.typing-dots::after {
    content: '';
    animation: typing 1.5s infinite;
}

@keyframes typing {
    0%, 20% { content: '.'; }
    40% { content: '..'; }
    60%, 80% { content: '...'; }
    100% { content: ''; }
}

/* Notification Badge */
.chat-notification {
    position: absolute;
    top: -5px;
    right: -5px;
    width: 20px;
    height: 20px;
    background: #ffffff;
    color: #000000;
    border: 2px solid #000000;
    border-radius: 50%;
    font-size: 11px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: bold;
    animation: pulse 2s infinite;
}

@keyframes pulse {
    0% { transform: scale(1); }
    50% { transform: scale(1.1); }
    100% { transform: scale(1); }
}

/* Mobile Responsive - Fullscreen Chat */
@media (max-width: 768px) {
    .chat-window {
        position: fixed;
        top: 0;
        left: 0;
        right: 0;
        bottom: 0;
        width: 100vw;
        height: 100vh;
        border-radius: 0;
        z-index: 10000;
        margin: 0;
    }
    
    .chat-widget {
        bottom: 20px;
        right: 20px;
    }
    
    .chat-toggle {
        width: 60px;
        height: 60px;
        font-size: 24px;
        z-index: 10001;
        position: fixed;
        bottom: 20px;
        right: 20px;
    }
    
    /* Hide toggle completely when chat is active on mobile */
    .chat-toggle.active {
        display: none !important;
    }
    
    /* Mobile close button in top right corner - only show on mobile */
    .mobile-close-btn {
        display: none;
        position: fixed;
        top: 15px;
        right: 15px;
        width: 40px;
        height: 40px;
        background: #000000;
        color: #ffffff;
        border: 2px solid #ffffff;
        border-radius: 50%;
        font-size: 18px;
        cursor: pointer;
        z-index: 10002;
        align-items: center;
        justify-content: center;
        box-shadow: 0 2px 10px rgba(0, 0, 0, 0.3);
        transition: all 0.2s ease;
    }
    
    .mobile-close-btn:hover {
        background: #333333;
        transform: scale(1.1);
    }
    
    /* Only show mobile close button on mobile devices when chat is active */
    @media (max-width: 768px) {
        .chat-window.active .mobile-close-btn {
            display: flex !important;
        }
    }
    
    .chat-header {
        padding: 20px;
        border-radius: 0;
    }
    
    .chat-messages {
        height: calc(100vh - 160px);
        padding: 15px 20px;
        padding-bottom: 80px; /* Extra space for fixed input */
    }
    
    .chat-input-container {
        padding: 15px 20px;
        border-radius: 0;
        position: fixed;
                bottom: 0;
        left: 0;
        right: 0;
        z-index: 999;
        background: #ffffff;
        border-top: 2px solid #000000;
        display: flex;
        gap: 10px;
        align-items: center;
        box-sizing: border-box;
    }
    
    /* Hide any close buttons in input area on mobile - but NOT send button */
    .chat-input-container .close:not(.chat-send),
    .chat-input-container .btn-close:not(.chat-send),
    .chat-input-container [class*="close"]:not(.chat-send):not([class*="send"]) {
        display: none !important;
    }
    
    .chat-input {
        font-size: 16px;
        padding: 12px 15px;
        /* Prevent zoom on iOS */
        -webkit-text-size-adjust: 100%;
        touch-action: manipulation;
        flex: 1;
        min-width: 0;
    }
    
    .chat-send {
        width: 45px;
        height: 45px;
        position: relative;
        z-index: 1000;
        flex-shrink: 0;
    }
    
    /* Mobile typing indicator */
    .typing-indicator {
        padding: 10px 20px;
        margin: 0;
        position: fixed;
        bottom: 80px; /* Above the input container */
        left: 0;
        right: 0;
        z-index: 998;
        background: #ffffff;
        border-top: 1px solid #000000;
    }
    
    /* Mobile message styling */
    .chat-message {
        margin-bottom: 15px;
    }
    
    .message-bubble {
        max-width: 85%;
        padding: 12px 16px;
        font-size: 16px;
        line-height: 1.5;
    }
    
    /* Mobile close button enhancement - only header close button visible */
    .chat-close {
        padding: 10px;
        font-size: 20px;
    }
    
    /* Hide bottom close button on mobile - but preserve send button and its contents */
    .chat-input-container .chat-close:not(.chat-send),
    .chat-window.active .bottom-close:not(.chat-send),
    .chat-window .chat-toggle {
        display: none !important;
    }
    
    /* Mobile-specific animations */
    .chat-window.active {
        animation: slideUpFullscreen 0.3s cubic-bezier(0.25, 0.46, 0.45, 0.94);
    }
    
    .chat-window:not(.active) {
        animation: slideDownFullscreen 0.3s cubic-bezier(0.25, 0.46, 0.45, 0.94);
    }
    
    /* Hide bottom close buttons and controls on mobile */
    .chat-window .bottom-controls,
    .chat-window .mobile-close-bottom {
        display: none !important;
    }
    
    /* Ensure send button is always visible and clickable */
    .chat-send {
        display: flex !important;
        pointer-events: auto !important;
        position: relative !important;
        z-index: 1001 !important;
        background: #000000 !important;
        color: #ffffff !important;
        border: 2px solid #000000 !important;
        align-items: center !important;
        justify-content: center !important;
    }
    
    /* Ensure send button icon is visible */
    .chat-send i,
    .chat-send .fa {
        display: inline-block !important;
        color: #ffffff !important;
        font-size: 16px !important;
        pointer-events: none !important;
    }
    
    /* Hide toggle when chat is open on mobile */
    .chat-window.active ~ .chat-toggle {
        display: none !important;
    }
}

@keyframes slideUpFullscreen {
    from {
        transform: translateY(100%);
        opacity: 0;
    }
    to {
        transform: translateY(0);
        opacity: 1;
    }
}

@keyframes slideDownFullscreen {
    from {
        transform: translateY(0);
        opacity: 1;
    }
    to {
        transform: translateY(100%);
        opacity: 0;
    }
}

/* Prevent body scroll when mobile chat is open */
@media (max-width: 768px) {
    body.mobile-chat-open {
        overflow: hidden;
        position: fixed;
        width: 100%;
        height: 100%;
    }
    
    /* Hide navbar header when mobile chat is open */
    body.mobile-chat-open .navbar,
    body.mobile-chat-open .navbar-header,
    body.mobile-chat-open .navbar-default,
    body.mobile-chat-open nav,
    body.mobile-chat-open header {
        display: none !important;
    }
    
    /* Alternative navbar hiding for different implementations */
    body.mobile-chat-open [class*="navbar"],
    body.mobile-chat-open [class*="nav-"],
    body.mobile-chat-open [class*="header"],
    body.mobile-chat-open .fixed-top,
    body.mobile-chat-open .navbar-fixed-top {
        display: none !important;
    }
    
    /* Additional iOS keyboard handling */
    .chat-window.active .chat-input-container {
        position: fixed;
        bottom: 0;
        left: 0;
        right: 0;
        z-index: 999;
        background: #ffffff;
        border-top: 2px solid #000000;
        box-shadow: 0 -2px 10px rgba(0, 0, 0, 0.1);
    }
    
    /* iOS viewport fix */
    @supports (-webkit-appearance: none) {
        .chat-window.active .chat-input-container {
            bottom: env(safe-area-inset-bottom, 0);
        }
    }
}

/* Tablet responsive */
@media (max-width: 1024px) and (min-width: 769px) {
    .chat-window {
        width: calc(100vw - 60px);
        height: 500px;
        right: 30px;
        left: 30px;
    }
}

/* Scrollbar Styling */
.chat-messages::-webkit-scrollbar {
    width: 8px;
}

.chat-messages::-webkit-scrollbar-track {
    background: #ffffff;
    border-radius: 0;
}

.chat-messages::-webkit-scrollbar-thumb {
    background: #000000;
    border-radius: 0;
    border: 1px solid #ffffff;
}

.chat-messages::-webkit-scrollbar-thumb:hover {
    background: #333333;
}

/* Fade in animation for messages */
@keyframes fadeInUp {
    from {
        opacity: 0;
        transform: translateY(10px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}
